﻿using System.Windows;
using System.Windows.Media.Animation;

namespace Comarch.Animation
{
    public class ExitEffects
    {
        internal protected ExitEffects(StoryboardBuilder storyboardBuilder)
        {
            StoryboardBuilder = storyboardBuilder;
        }
        public StoryboardBuilder StoryboardBuilder { get; private set; }

        public StoryboardBuilder FlyOut(FrameworkElement element, FlyDirection direction = FlyDirection.Left, int duration = 300, IEasingFunction easingFunction = null)
        {
            var translate = TranslationCalculator.CalculateTranslationPoint(direction, element);
            easingFunction = easingFunction ?? new CubicEase();
            return StoryboardBuilder.Translate(element, (int)-translate.X, (int)-translate.Y, duration, easingFunction);
        }

        public StoryboardBuilder RemoveWidthEntry(FrameworkElement element, int duration = 300, IEasingFunction easingFunction = null)
        {
            const int destValue = 0;
            element.Opacity = 1;
            easingFunction = easingFunction ?? new CubicEase { EasingMode = EasingMode.EaseOut };
            StoryboardBuilder.AddDoubleKeyFrames(element, "Width", destValue, duration, easingFunction, false);
            return StoryboardBuilder;
        }

        public StoryboardBuilder RemoveHeightEntry(FrameworkElement element, int duration = 300, IEasingFunction easingFunction = null)
        {
            const int destValue = 0;
            element.Opacity = 1;
            easingFunction = easingFunction ?? new CubicEase { EasingMode = EasingMode.EaseOut };
            StoryboardBuilder.AddDoubleKeyFrames(element, "Height", destValue, duration, easingFunction, false);
            return StoryboardBuilder;
        }
    }
}